package com.ruoyi.web.controller.video;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.exchangeCode.domain.ExchangeCode;
import com.ruoyi.exchangeCode.service.IExchangeCodeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 兑换码Controller
 * 
 * @author zunzun
 * @date 2023-11-22
 */
@RestController
@RequestMapping("/exchangeCode/exchangeCode")
public class ExchangeCodeController extends BaseController
{
    @Autowired
    private IExchangeCodeService exchangeCodeService;

    /**
     * 查询兑换码列表
     */
    @PreAuthorize("@ss.hasPermi('exchangeCode:exchangeCode:list')")
    @GetMapping("/list")
    public TableDataInfo list(ExchangeCode exchangeCode)
    {
        startPage();
        List<ExchangeCode> list = exchangeCodeService.selectExchangeCodeList(exchangeCode);
        return getDataTable(list);
    }

    /**
     * 导出兑换码列表
     */
    @PreAuthorize("@ss.hasPermi('exchangeCode:exchangeCode:export')")
    @Log(title = "兑换码", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExchangeCode exchangeCode)
    {
        List<ExchangeCode> list = exchangeCodeService.selectExchangeCodeList(exchangeCode);
        ExcelUtil<ExchangeCode> util = new ExcelUtil<ExchangeCode>(ExchangeCode.class);
        util.exportExcel(response, list, "兑换码数据");
    }

    /**
     * 获取兑换码详细信息
     */
    @PreAuthorize("@ss.hasPermi('exchangeCode:exchangeCode:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(exchangeCodeService.selectExchangeCodeById(id));
    }

    /**
     * 新增兑换码
     */
    @PreAuthorize("@ss.hasPermi('exchangeCode:exchangeCode:add')")
    @Log(title = "兑换码", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExchangeCode exchangeCode)
    {
        return toAjax(exchangeCodeService.insertExchangeCode(exchangeCode));
    }
    /**
     * 新增兑换码
     */
    @PreAuthorize("@ss.hasPermi('exchangeCode:exchangeCode:add')")
    @Log(title = "批量兑换码", businessType = BusinessType.OTHER)
    @PostMapping("/addLista")
    public AjaxResult addLista(@RequestBody ExchangeCode exchangeCode)
    {
        return toAjax(exchangeCodeService.insertExchangeCodeList(exchangeCode));
    }
    /**
     * 修改兑换码
     */
    @PreAuthorize("@ss.hasPermi('exchangeCode:exchangeCode:edit')")
    @Log(title = "兑换码", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExchangeCode exchangeCode)
    {
        return toAjax(exchangeCodeService.updateExchangeCode(exchangeCode));
    }

    /**
     * 删除兑换码
     */
    @PreAuthorize("@ss.hasPermi('exchangeCode:exchangeCode:remove')")
    @Log(title = "兑换码", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(exchangeCodeService.deleteExchangeCodeByIds(ids));
    }
}
